package com.credit.zxqr.controller;

import java.util.ArrayList;
import java.util.List;

import com.credit.common.utils.StringUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.credit.common.annotation.Log;
import com.credit.common.core.controller.BaseController;
import com.credit.common.core.domain.AjaxResult;
import com.credit.common.enums.BusinessType;
import com.credit.zxqr.domain.CreditXzqr;
import com.credit.zxqr.service.ICreditXzqrService;
import com.credit.common.utils.poi.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;
import com.credit.common.core.page.TableDataInfo;

/**
 * 行政确认Controller
 * 
 * @author credit
 * @date 2025-03-24
 */
@RestController
@RequestMapping("/credit-new/xzqr/creditXzqr")
public class CreditXzqrController extends BaseController
{
    @Autowired
    private ICreditXzqrService creditXzqrService;

    /**
     * 查询行政确认列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CreditXzqr creditXzqr)
    {
        startPage();
        List<CreditXzqr> list = creditXzqrService.selectCreditXzqrList(creditXzqr);
        return getDataTable2(list);
    }

    /**
     * 导出行政确认列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, CreditXzqr creditXzqr)
    {
        List<CreditXzqr> list = creditXzqrService.selectCreditXzqrList(creditXzqr);
        ExcelUtil<CreditXzqr> util = new ExcelUtil<CreditXzqr>(CreditXzqr.class);
        util.exportExcel(response, list, "行政确认数据");
    }

    /**
   * 下载行政确认导入模版
   */
    @RequestMapping("/downloadImportMB")
    public void downloadImportMB(HttpServletResponse response)
    {
        List<CreditXzqr> list = new ArrayList<>();
        ExcelUtil<CreditXzqr> util = new ExcelUtil<CreditXzqr>(CreditXzqr.class);
        util.exportExcel(response, list, "行政确认");
    }

    /**
     * 导入行政确认数据
     */
    @RequestMapping("/importData")
    public AjaxResult importData(MultipartFile excelfile) throws Exception
    {
        ExcelUtil<CreditXzqr> util = new ExcelUtil<>(CreditXzqr.class);
        List<CreditXzqr> list = util.importExcel(excelfile.getInputStream());
        String message = creditXzqrService.importData(list);
        return success(message);
    }
    /**
     * 获取行政确认详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success2(creditXzqrService.selectCreditXzqrById(id));
    }

    /**
     * 新增行政确认
     */
    @PostMapping
    public AjaxResult add(@RequestBody CreditXzqr creditXzqr)
    {
        return toAjax2(creditXzqrService.insertCreditXzqr(creditXzqr));
    }

    /**
     * 修改行政确认
     */
    @PutMapping
    public AjaxResult edit(@RequestBody CreditXzqr creditXzqr)
    {
        return toAjax2(creditXzqrService.updateCreditXzqr(creditXzqr));
    }

    /**
     * 删除行政确认
     */
	@DeleteMapping("/delete")
    public AjaxResult remove(@RequestParam(value = "ids", defaultValue = "", required = true) String id)
    {
        if(StringUtils.isNotEmpty(id)){
            String[] ids = id.split(",");
            return toAjax2(creditXzqrService.deleteCreditXzqrByIds(ids));
        }
        return toAjax2(0);
    }
}
